package cn.zz.veggie.web.controller.mgmt;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.core.types.result.PageResult;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.DelManAppService;
import cn.zz.veggie.web.types.dto.mgmt.user.MgmtDelManQueryDto;
import cn.zz.veggie.web.types.dto.mgmt.user.MgmtDelManSaveDto;
import cn.zz.veggie.web.types.vo.his.user.HisDelManVo;
import cn.zz.veggie.web.types.vo.mgmt.user.MgmtDelManVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * 管理端/配送员
 * 
 * @author zhongq
 * @since 2024/7/14
 */
@Validated
@RestController
@BoxRespResult
@RequiredArgsConstructor
@RequestMapping("/mgmt/del-man")
public class MgmtDelManController {

	private final DelManAppService delManAppService;

	/**
	 * 简单搜索
	 */
	@GetMapping("/search")
	public List<HisDelManVo> search(String keyword) {
		return delManAppService.mgmtSearch(keyword);
	}

	/**
	 * 配送员列表
	 */
	@GetMapping("/list")
	public PageResult<MgmtDelManVo> list(@Validated MgmtDelManQueryDto dto,
			@RequestParam(defaultValue = "1") @Positive Integer current,
			@RequestParam(defaultValue = "10") @Positive Integer size) {
		return delManAppService.mgmtGetList(dto, PageQuery.of(current, size));
	}

	/**
	 * 添加配送员
	 */
	@PostMapping("/save")
	public void save(@RequestBody @Validated MgmtDelManSaveDto dto) {
		delManAppService.mgmtSaveDelMan(dto);
	}

}